package com.example.administrator.testproject.MVP.PullRefresh;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

import com.example.administrator.testproject.MVP.Base.BaseActivity;
import com.example.administrator.testproject.R;
import com.example.administrator.testproject.Wiget.PullRefresh.PullRefreshView;
import com.example.administrator.testproject.Wiget.PullRefresh.interfaces.OnFreshListener;
import com.example.administrator.testproject.Wiget.container.DefaultFooter;
import com.example.administrator.testproject.Wiget.container.DefaultHeader;

import butterknife.BindView;

/**
 * Created by Administrator on 2016/10/24 0024.
 */

public class TestMainActivity extends BaseActivity implements OnFreshListener {

    @BindView(R.id.stack_info_springview)
    PullRefreshView stackInfoSpringview;
    @BindView(R.id.webView)
    WebView webView;

    @Override
    protected int setContentViews() {
        return R.layout.testpullrefresh_layout;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        stackInfoSpringview = (SpringView) findViewById(R.id.stack_info_springview);
        stackInfoSpringview.setListener(this);
        stackInfoSpringview.setHeader(new DefaultHeader(TestMainActivity.this));
        stackInfoSpringview.setFooter(new DefaultFooter(TestMainActivity.this));
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000 * 3);
                    stackInfoSpringview.onFinishFreshAndLoad();//刷新完成
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        webView.setWebViewClient(new WebViewClient(){
            //页面内部事件监听
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, final String url) {
                return super.shouldOverrideUrlLoading(view, url);
            }
        });
    }

    @Override
    public void onRefresh() {
        webView.loadUrl("http://www.xincheping.com/views/97272.html");
        stackInfoSpringview.onFinishFreshAndLoad();//刷新完成
        Toast.makeText(this, "onRefresh", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onLoadmore() {
        webView.loadUrl("http://www.xincheping.com/views/97272.html");
        stackInfoSpringview.onFinishFreshAndLoad();//刷新完成
        Toast.makeText(this, "onLoadmore", Toast.LENGTH_LONG).show();
    }
}
